import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.TextArea;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridLayout;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class EILogin extends JFrame{
	
	private JPanel contentPane;
	JButton botoia = new JButton("Sartu");
	JLabel nan = new JLabel("NAN zenbakia sartu:");
	JLabel pasahitza = new JLabel("Pasahitza sartu:");
	JTextField nanSartu = new JTextField();
	JTextField pasahitzaSartu = new JPasswordField();
	JPanel panel1 = new JPanel();
	JPanel panel2 = new JPanel();
	String lana = null;
	String nanZenb;
	String pasa;
	public static boolean administratzailea;
	
	
	public EILogin(){ //eraikitzailea
		
		osagaiakHasieratu();
		botoiaHasieratu();
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
			
	}
	
	public void osagaiakHasieratu(){
		
		this.setSize(700,500);
		this.setTitle("Login");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNanZenbakiaSartu = new JLabel("NAN zenbakia sartu:");
		lblNanZenbakiaSartu.setBounds(283, 141, 145, 15);
		contentPane.add(lblNanZenbakiaSartu);
		
		JLabel lblPasahitza = new JLabel("Pasahitza:");
		lblPasahitza.setBounds(323, 221, 90, 15);
		contentPane.add(lblPasahitza);
		
		nanSartu = new JTextField();
		nanSartu.setBounds(455, 139, 114, 19);
		contentPane.add(nanSartu);
		nanSartu.setColumns(10);
		
		pasahitzaSartu = new JPasswordField();
		pasahitzaSartu.setBounds(455, 219, 114, 19);
		contentPane.add(pasahitzaSartu);
		pasahitzaSartu.setColumns(10);
		
		JLabel lblMaster = new JLabel("MASTER");
		lblMaster.setFont(new Font("Dialog", Font.BOLD, 22));
		lblMaster.setBounds(385, 50, 161, 40);
		contentPane.add(lblMaster);
		
		botoia = new JButton("Sartu");
		botoia.setBounds(381, 290, 129, 51);
		contentPane.add(botoia);
		
	}
	
	public void botoiaHasieratu(){
		botoia.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				nanZenb=nanSartu.getText();
				pasa= pasahitzaSartu.getText();
				lana = ErabiltzaileKudeatzailea.getInstantzia().erabKonprobatu(nanZenb,pasa);
				if ("Admin".equalsIgnoreCase(lana)){
					administratzailea = true;
					EIAdministratzailea admin = new EIAdministratzailea();
					EILogin.this.dispose();
				}else if ("Idazkaria".equalsIgnoreCase(lana)){
					administratzailea = false;
					EIIdazkari idazkari = new EIIdazkari();
					EILogin.this.dispose();
				}else{
					try {
						EIErrorea dialog = new EIErrorea();
						dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
						dialog.setVisible(true);
					} catch (Exception ex) {
						ex.printStackTrace();
					}
				}
			}
		});
		
	}
	public static void main (String[]args){
		EILogin frame = new EILogin();
		
		
	}

}
